/* eslint-disable no-unused-vars */
// 获取供应商帐单下的签约方:客服系统
import React from 'react';
import { Select, Spin } from 'antd';
import HOCSelect from '@/components/AntDesign/Select';
import { getBillSupplyList } from '@/services/api';
import PropTypes from 'prop-types';

const { Option } = Select;

class BillSupplierWithState extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      billSupplyList: [],
      loading: false,
    };
  }

  async componentDidMount() {
    const { dispatch, params = {} } = this.props;
    this.setState({ loading: true });
    try {
      const response = await getBillSupplyList(params);
      this.setState({
        billSupplyList: Array.isArray(response.data) ? response.data : [],
        loading: false,
      });
    } catch (e) {
      console.error(e);
    } finally {
      this.setState({ loading: false });
    }
  }

  render() {
    const { getData, value, labelInValue, ...rest } = this.props;
    const { loading, billSupplyList } = this.state;
    return (
      <HOCSelect
        placeholder="请输入关键字检索"
        {...rest}
        showSearch
        labelInValue={labelInValue}
        value={labelInValue ? value : value?.title}
        optionFilterProp="children"
        notFoundContent={loading ? <Spin size="small" /> : '暂无数据'}
        onSelect={(selectValue, options) => getData(selectValue, options)}
        showArrow={false}
      >
        {billSupplyList.map(item => (
          <Option key={item.suppId} fsOptions={item} title={item.name}>
            {item.name}
          </Option>
        ))}
      </HOCSelect>
    );
  }
}
BillSupplierWithState.defaultProps = {
  getData: () => {},
  params: {},
};
BillSupplierWithState.propTypes = {
  getData: PropTypes.func,
  params: PropTypes.object,
};
export default BillSupplierWithState;
